package com.netease.nim.uikit.business.session.actions;

import com.google.gson.Gson;
import com.netease.nim.uikit.R;
import com.netease.nim.uikit.business.util.Des3Util;
import com.netease.nim.uikit.net.SharedHelper;
import com.netease.nim.uikit.net.entity.BaseBean;
import com.netease.nim.uikit.net.entity.CheckModel;
import com.netease.nim.uikit.net.rxjava.HttpMethods;
import com.netease.nim.uikit.net.subscribers.ProgressSubscriber;
import com.netease.nim.uikit.net.subscribers.SubscriberOnNextListener;
import com.netease.nimlib.sdk.msg.MessageBuilder;
import com.netease.nimlib.sdk.msg.model.IMMessage;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/17
 */
public class SImageAction extends PickImageAction {

    public SImageAction() {
        super(R.drawable.nim_message_plus_photo_selector, R.string.input_s_panel_photo, false);
    }

    @Override
    protected void onPicked(File file) {
        SubscriberOnNextListener<BaseBean> onNextListener = baseBean -> {
            SImageAttachment attachment = new SImageAttachment();
            attachment.setPath(file.getPath());
            attachment.setSize(file.length());
            IMMessage message = MessageBuilder.createCustomMessage(getAccount(), getSessionType(), attachment);
            Map<String,Object> map=new HashMap<>();
            map.put("image_type",0);
            message.setLocalExtension(map);
            sendMessage(message);
        };
        CheckModel regModel = new CheckModel();//登录上传参数
        regModel.setMemberId(SharedHelper.readId(getContainer().activity));
        regModel.setOtherMemberId(getContainer().account);
        regModel.setContent(file.getAbsolutePath());
        regModel.setType(0);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(regModel));
        HttpMethods.getInstance().checkMsg(new ProgressSubscriber<>(onNextListener, getContainer().activity, true), requestBody);

    }


}

